import { menuList } from '@/api/menu_api';
import { generateMenus, generateRoutes } from '@/router/navmenu';

type Commit = {
    commit: (a:string, data:any) => void;
    // state: State
    [propName: string]: any;
}

export default {
    // labels ability
    SET_LABELS({commit}: Commit, data:any):void {
        commit('SET_LABELS', data);
    },
    DEL_LABELS({commit}: Commit, data:any) {
        commit('DEL_LABELS', data);
    },
    // user ability
    SET_UINFO({commit}: Commit, data:any) {
        commit('SET_UINFO', data);
    },
    // member grade
    SET_GRADES({commit}: Commit, data:any) {
        commit('SET_GRADES', data);
    },
    // menus
    SET_MENUS({commit, state}: Commit) {
        const state_menus = state.uinfo.roles.menus;
        return new Promise(resolve => {
            // menuList().then(response => {
            //     const res = response.data;
            //     if(res.s) {
                    // 角色路由权限
                    // const arr = [];
                    // state_menus.forEach(item => {
                    //     res.d.forEach(ite => {
                    //         if(item == ite._id) {
                    //             arr.push(ite);
                    //         }
                    //     })
                    // })
                    const routes = generateRoutes(state_menus);
                    // commit('SET_ORIGIN_MENUS', res.d);
                    commit('SET_ROUTES', routes);
                    // commit('SET_MENUS', menus);
                    resolve(routes);
                // }
            // })
        })
    }
}